package cn.dfusion.config;

import cn.dfusion.auth.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author ipenta
 * @ClassName: WebMvcConfig
 * @Description: TODO
 * @date 2017-09-26 上午8:43
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

	private final AuthenticationInterceptor authenticationInterceptor;

	@Autowired
	public WebMvcConfig(AuthenticationInterceptor authenticationInterceptor) {
		this.authenticationInterceptor = authenticationInterceptor;
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(authenticationInterceptor).excludePathPatterns("/").excludePathPatterns("/docs").excludePathPatterns("/auth/**");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**")
				.addResourceLocations("classpath:/static/");
	}


}
